package com.xxx.mch.controller;

import com.xxx.mch.domain.dto.GenresTemplateDto;
import com.xxx.mch.service.GenresService;
import com.xxx.mch.utils.WrapMapper;
import com.xxx.mch.utils.Wrapper;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author FengHaixin
 * @description 一句话描述该文件的用途
 * @date 2020-09-12
 */
@RestController
@RequestMapping ("genres")
@Api (tags = "体裁接口")
public class GenresController
{
    @Autowired
    private GenresService genresService;


    @ApiOperation ("查询体裁分设置接口")
    @GetMapping (value = "template", produces = MediaType.APPLICATION_JSON_VALUE)
    public Wrapper<List<GenresTemplateDto>> getTemplate()
    {
        return WrapMapper.ok(genresService.getTemplate());
    }


    @ApiOperation ("创建体裁分设置接口")
    @PostMapping (value = "template", consumes = MediaType.APPLICATION_JSON_VALUE, produces = MediaType.APPLICATION_JSON_VALUE)
    public Wrapper<String> createTemplate(@RequestBody List<GenresTemplateDto> templates)
    {
        genresService.createTemplate(templates);
        return WrapMapper.ok();
    }


    @ApiOperation ("更新体裁分设置接口")
    @PutMapping (value = "template", consumes = MediaType.APPLICATION_JSON_VALUE, produces = MediaType.APPLICATION_JSON_VALUE)
    public Wrapper<List<GenresTemplateDto>> updateTemplate(@RequestBody List<GenresTemplateDto> templates)
    {
        genresService.updateTemplate(templates);
        return WrapMapper.ok();
    }

    @ApiOperation ("删除体裁分接口")
    @DeleteMapping (value = "template{id}", consumes = MediaType.APPLICATION_JSON_VALUE, produces = MediaType.APPLICATION_JSON_VALUE)
    public Wrapper<String> deleteTemplate(@PathVariable Integer id)
    {
        genresService.deleteTemplate(id);
        return WrapMapper.ok();
    }
}
